package DesignPattern;

import java.util.ArrayList;

public class Build {
    public static void main(String[] args) {
        MealBuilder mb = new MealBuilder();
        Meal meal = mb.prepareVegMeal();
        System.out.println("套餐价格："+meal.getCost());
        meal.showItem();
    }
}

class MealBuilder{
    public Meal prepareVegMeal(){
        Meal meal = new Meal();
        meal.addItem(new Coke());
        meal.addItem(new ChickBurger());
        return meal;
    }
}

class Meal{
    private ArrayList<Item> items = new ArrayList<Item>();

    public void addItem(Item item){
        items.add(item);
    }

    public float getCost(){
        float cost = 0.0f;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    public void showItem(){
        for (Item item : items) {
            System.out.println(item.name());
            System.out.println(item.price());
            System.out.println(item.packing());
        }
    }
}


interface Item{
    public String name();
    public Packing packing();
    public float price();
}
interface Packing{
    public String packing();
}

class Wrapper implements Packing{
    @Override
    public String packing() {
        return "Wrapper";
    }
}

class Bottle implements Packing{
    @Override
    public String packing() {
        return "Bottle";
    }
}

abstract class Burger implements Item{
    @Override
    public Packing packing() {
        return new Wrapper();
    }
}

abstract class ColdDrink implements Item{

    @Override
    public Packing packing() {
        return new Bottle();
    }
}

class ChickBurger extends Burger{

    @Override
    public String name() {
        return "burger";
    }

    @Override
    public float price() {
        return 22.5f;
    }
}

class Coke extends ColdDrink{

    @Override
    public String name() {
        return "coke";
    }

    @Override
    public float price() {
        return 3.5f;
    }
}


